package com.bwie.controller;

import com.bwie.pojo.TUser;
import com.bwie.service.TUserService;
import com.bwie.utils.R;
import com.bwie.vo.LoginInfoVo;
import com.bwie.vo.LoginVo;
import com.bwie.vo.PageInfoVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author:杨珂
 * @CreateTime: 2025-03-21
 */

@RestController
@RequestMapping("/user/index")
@RefreshScope
public class IndexController {


    @Autowired
    private TUserService tUserService;

    @Value("${site.className}")
    private String className;

    /**
     * 根据id获取用户信息
     *
     * @param id
     * @return
     */
    @PostMapping("/getUserById/{id}")
    public R getUserById(@PathVariable("id") Integer id) {
        return tUserService.getUserById(id);
    }

    /**
     * 管理员登录
     *
     * @return
     */
    @PostMapping("/login")
    public R login(@RequestBody LoginVo loginVo) {

        return tUserService.login(loginVo);

    }

    /**
     * 用户列表多条件分页查询
     *
     * @param pageInfoVo
     * @return
     */
    @ApiOperation("用户分页条件查询")
    @PostMapping("/getUserList")
    public R getUserList(@RequestBody PageInfoVo pageInfoVo) {

        return tUserService.getUserList(pageInfoVo);

    }

    /**
     * 商户注册
     *
     * @param tUser
     * @return
     */
    @ApiOperation("商户注册")
    @PostMapping("/addUser")
    public R addUser(@RequestBody TUser tUser) {
        return tUserService.addUser(tUser);
    }

    /**
     * 从nacos中读取数据
     *
     * @return
     */
    @PostMapping("/getConfigFromNacos")
    public R getConfigFromNacos() {
        return tUserService.getConfigFromNacos();
    }

    /**
     * 从nacos中读取数据 不使用配置类
     *
     * @return
     */
    @PostMapping("/getConfigFromNacos2")
    public R getConfigFromNacos2() {
        System.out.println("className=" + className);
        return R.OK(className);
    }

    @PostMapping("/uploadImage")
    public R uploadImage(@RequestPart("file") MultipartFile file) {
        return tUserService.uploadImage(file);
    }


    /**
     * 获取用户角色列表
     *
     * @param id
     * @return
     */
    @ApiOperation("获取用户角色列表")
    @PostMapping("/getUserRole/{id}")
    public R getUserRole(@PathVariable("id") Integer id) {
        return tUserService.getUserRole(id);
    }

    /**
     * 审核
     *
     * @return
     */
    @ApiOperation("审核")
    @PostMapping("/checkUser")
    public R checkUser(@RequestBody TUser tUser) {
        return tUserService.checkUser(tUser);
    }

    @PostMapping("/updateUser")
    public R updateUser(@RequestBody TUser tUser) {
        return tUserService.updateUser(tUser);
    }

    /**
     * 根据ID删除用户
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id删除用户")
    @PostMapping("/delUserById/{id}")
    public R delUserById(@PathVariable("id") Integer id) {
        return tUserService.delUserById(id);
    }

    /**
     * 批量删除用户
     *
     * @param userList
     * @return
     */
    @ApiOperation("批量删除")
    @PostMapping("/delUserAll")
    public R delUserAll(@RequestBody List<TUser> userList) {
        return tUserService.delUserAll(userList);
    }
}
